#ifdef SYPX_MEMCHECK
#include "mmgr.h"
#endif

#include "Actor.h"
#include "Actors.h"
#include "Level.h"

namespace SheepDefence 
{
	Actor::Actor()
	{
	}

	Actor::~Actor()
	{
	}

	Actor* Actor::loadActor(const SypX::String& filename)
	{
		SypX::FileInputStream fin;
		SypX::String temp;
		SypX::Sprite* sprite;

		SypX::String path = SypX::Engine::getFilePath(filename);
		fin.open( path.c_str());		//load actor file

		// Sprite
		std::getline(fin, temp);		//read in sprite filename
		sprite = SypX::Sprite::loadSpriteFromFile(SypX::Engine::getFilePath(temp));
		
		// Type of Actor
		std::getline(fin, temp);

		if (temp == "Wolf")
		{
			return new Wolf(fin, sprite);
		}
		else if (temp == "Dog")
		{
			return new Dog(fin, sprite);
		}
		else if (temp == "Sheep")
		{
			return new Sheep(fin, sprite);
		}
		else if (temp == "Obstacle")
		{
			return new Obstacle(fin, sprite);
		}
		
		assert("Unkown Actor type encountered...");
		return 0;	//unknown type
	}

	void Actor::draw()
	{
		sprite->drawBufferedInstances();
	}
}